package com.example.warehouse.bus.controller;

import com.example.warehouse.bus.pojo.param.BusSalesbackSelectParam;
import com.example.warehouse.bus.pojo.param.BusSalesbackUpdateParam;
import com.example.warehouse.bus.service.IBusSalesbackService;
import com.example.warehouse.common.security.CurrentPrincipal;
import com.example.warehouse.common.web.JsonResult;
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.security.core.annotation.AuthenticationPrincipal;
import org.springframework.web.bind.annotation.*;
import springfox.documentation.annotations.ApiIgnore;

/**
 * 销售退货订单_板块控制层
 * pipibee
 */
@Slf4j
@RequestMapping("/busSalesback")
@RestController
@Api(tags = "6.2. 销售退货订单_管理")
public class BusSalesbackController {

    @Autowired
    private IBusSalesbackService iBusSalesbackService;

    public BusSalesbackController() {
        log.info("创建控制器对象:BusSalesbackController");
    }

    @ApiOperation("新增_销售退货订单")
    @ApiOperationSupport(order = 100)
    @PreAuthorize("hasAuthority('/busSalersback/add-new')")
    @PostMapping("/add-new")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "销售订单ID", required = true, dataType = "Long"),
            @ApiImplicitParam(name = "description", value = "备注", required = true, dataType = "String")
    })
    public JsonResult addNew(Long id, String description, @AuthenticationPrincipal @ApiIgnore CurrentPrincipal currentPrincipal) {
        log.debug("开始处理【新增_销售退货订单】的请求，参数：{},{},{}", id, description, currentPrincipal);
        iBusSalesbackService.addNew(id, description, currentPrincipal);
        return JsonResult.ok();
    }

    @ApiOperation("逻辑删除_销售退货订单")
    @ApiOperationSupport(order = 200)
    @PreAuthorize("hasAuthority('/busSalersback/delete')")
    @PostMapping("/delete")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "销售退货订单ID", required = true, dataType = "Long")
    })
    public JsonResult delete(Long id, @AuthenticationPrincipal @ApiIgnore CurrentPrincipal currentPrincipal) {
        log.debug("开始处理【逻辑删除_销售退货订单】的请求，参数：{},{}", id, currentPrincipal);
        iBusSalesbackService.delete(id, currentPrincipal);
        return JsonResult.ok();
    }

    @ApiOperation("任意项更改_销售退货订单")
    @ApiOperationSupport(order = 300)
    @PreAuthorize("hasAuthority('/busSalersback/update')")
    @PostMapping("/update")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "销售退货订单ID", required = true, dataType = "Long"),
            @ApiImplicitParam(name = "customerId", value = "顾客ID", required = false, dataType = "Long"),
            @ApiImplicitParam(name = "goodsId", value = "商品ID", required = false, dataType = "Long"),
            @ApiImplicitParam(name = "payType", value = "支付类型", required = false, dataType = "String"),
            @ApiImplicitParam(name = "salesbackPrice", value = "退货价格", required = false, dataType = "BigDecimal"),
            @ApiImplicitParam(name = "number", value = "退货数量", required = false, dataType = "Integer"),
            @ApiImplicitParam(name = "description", value = "备注", required = false, dataType = "String"),
            @ApiImplicitParam(name = "approvalStatus", value = "审批状态", required = false, dataType = "Integer")
    })
    public JsonResult update(BusSalesbackUpdateParam busSalesbackUpdateParam, @AuthenticationPrincipal @ApiIgnore CurrentPrincipal currentPrincipal) {
        log.debug("开始处理【更改_销售退货订单】的请求，参数：{},{}", busSalesbackUpdateParam, currentPrincipal);
        iBusSalesbackService.update(busSalesbackUpdateParam, currentPrincipal);
        return JsonResult.ok();
    }


    @ApiOperation("审批_销售退货订单")
    @ApiOperationSupport(order = 310)
    @PreAuthorize("hasAuthority('/busSalersback/update')")
    @PostMapping("/approval")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "销售退货订单ID", required = true, dataType = "Long"),
            @ApiImplicitParam(name = "approval", value = "审批结果", required = true, dataType = "Integer")
    })
    public JsonResult approvalSalesback(Long id, Integer approval, @AuthenticationPrincipal @ApiIgnore CurrentPrincipal currentPrincipal) {
        log.debug("开始处理【审批_销售退货订单】的请求，参数：{},{},{}", id, approval, currentPrincipal);
        iBusSalesbackService.approvalSalesback(id, approval, currentPrincipal);
        return JsonResult.ok();
    }

    @ApiOperation("分页模糊查询_销售退货订单")
    @ApiOperationSupport(order = 400)
    @PreAuthorize("hasAuthority('/busSalersback/select')")
    @PostMapping("/select")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "customerName", value = "客户名称", required = false, dataType = "String"),
            @ApiImplicitParam(name = "goodsName", value = "货物名称", required = false, dataType = "String"),
            @ApiImplicitParam(name = "idpipo", value = "操作人ID", required = false, dataType = "Long"),
            @ApiImplicitParam(name = "begin", value = "开始时间", required = false, dataType = "LocalDate"),
            @ApiImplicitParam(name = "end", value = "结束时间", required = false, dataType = "LocalDate"),
            @ApiImplicitParam(name = "approvalStatus", value = "审批状态", required = false, dataType = "Integer"),
            @ApiImplicitParam(name = "page", value = "目标页码", required = false, dataType = "Integer"),
            @ApiImplicitParam(name = "pageSize", value = "每页大小", required = false, dataType = "Integer")
    })
    public JsonResult select(BusSalesbackSelectParam busSalesbackSelectParam, @RequestParam(defaultValue = "1") Integer page, @RequestParam(defaultValue = "5") Integer pageSize) {
        log.debug("开始处理【分页模糊查询_销售退货订单】的请求，参数：{},{},{}", busSalesbackSelectParam, page, pageSize);
        return JsonResult.ok(iBusSalesbackService.page(busSalesbackSelectParam, page, pageSize));
    }


}
